home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 42
/
Amiga Format AFCD42 (Issue 126, Aug 1999).iso
/
-serious-
/
programming
/
amos
/
mazer
/
bigmazer.amos
/
bigmazer.amosSourceCode
< prev
next >
Wrap
AMOS Source Code
|
1999-05-17
|
2KB
|
112 lines
'This program creates mazes!
'
Dim MAZE(16,9),FLAGS(16,9)
For B=0 To 9
For A=0 To 16
FLAGS(A,B)=15
Next
Next
For A=0 To 16
Add FLAGS(A,0),-1 : Rem No N exit on N row
Add FLAGS(A,9),-4 : Rem No S exit on S row
If A<10
Add FLAGS(16,A),-2 : Rem No E exit on E row
Add FLAGS(0,A),-8 : Rem No W exit on W row
End If
Next
Dim DIX(3),DIY(3)
DIY(0)=-1 : DIX(1)=1 : DIY(2)=1 : DIX(3)=-1
'
'Here we go...
'
FIRST=True : Randomize Timer
GO1:
'
Ink 0 : Rem Every time to draw maze!
If FIRST
Curs Off : Hide On : Paper 2 : Cls : No Mask
Else
For A=0 To 16 : For B=0 To 9 : MAZE(A,B)=0 : Next : Next
End If
'
For A=0 To 323 Step 19
Draw A,0 To A,190 : If A<199 Then Draw 0,A To 323,A
Next
Ink 2
'
'Start position
'
X=Rnd(16) : Y=Rnd(9) : VISITED=0
'
Do
If VISITED=169 Then Goto SLUTT
BX=X*19+2 : BY=Y*19+2
Paste Bob BX,BY,1
NX=BX : NY=BY
'
DI=Rnd(3) : OD=DI : D$=""
'Build list of exits
For T=1 To 4 : P2=2^DI
If(FLAGS(X,Y) and P2)=P2
If MAZE(X+DIX(DI),Y+DIY(DI))=0
D$=D$+Chr$(DI+64)
End If
End If
Add DI,1,0 To 3
Next
If D$>""
'Pick and move
DI=Asc(D$)-64 : P2=2^DI : NX=BX+19*DIX(DI) : NY=BY+19*DIY(DI)
FLYTT
MAZE(X,Y)=MAZE(X,Y) or P2
Add X,DIX(DI) : Add Y,DIY(DI)
DI=(DI+2) and 3
MAZE(X,Y)=MAZE(X,Y) or(2^DI)
Inc VISITED
Else
'Scan for used room
Repeat
Wait 2
Bar BX,BY To BX+15,BY+15
Add X,1,0 To 16
If X=0 : Add Y,1,0 To 9 : End If
BX=X*19+2 : BY=Y*19+2
Paste Bob BX,BY,1
Until MAZE(X,Y)>0
End If
Loop
'
Procedure FLYTT
Shared BX,BY,NX,NY
If NX<>BX
D=(NX-BX) : D=D/Abs(D)
Repeat : Add BX,D : Paste Bob BX,BY,1 : Wait Vbl : Until BX=NX
End If
If NY<>BY
D=(NY-BY) : D=D/Abs(D)
Repeat : Add BY,D : Paste Bob BX,BY,1 : Wait Vbl : Until BY=NY
End If
End Proc
SLUTT:
Wait 25
Bar BX,BY To BX+15,BY+15
'
'Store the maze and go back for another
'
If Exist("bMazes")
Append 1,"bMazes"
Else
Open Out 1,"bMazes"
End If
For B=0 To 9 : For A=0 To 16
Print #1,Chr$(MAZE(A,B)+64);
Next : Next
Print #1,""
Close
FIRST=False
Pen 0 : Print At(14,24);"Another? y/n";
X$=Inkey$ : X$=""
While X$="" : X$=Lower$(Inkey$) : Wend
If X$="y" Then Print At(14,24);Space$(12); : Goto GO1
Default
Print : Centre "Okay then... later!" : Print